package com.uroad.lib.imageloader;

import android.widget.ImageView;

import com.uroad.lib.R;

/**
 * Created by jiadong on 2016/11/2.
 * encapsulation of ImageView,Build Pattern used
 */

public class ImageLoader {
    private int quality;  //图片质量 (RGB_565，ARGB_8888)
    private String url; //需要解析的url
    private int error; //当没有成功加载的时候显示的图片
    private int placeHolder; //正在加载的时候显示的图片
    private int transform; //对图片进行裁剪
    private int radius; //圆角图片角度
    private float thumbnail; //图片缩略比例
    private boolean needCache; //是否需要缓存图片
    private ImageView imgView;

    private ImageLoader(Builder builder) {
        this.quality = builder.quality;
        this.url = builder.url;
        this.error = builder.error;
        this.placeHolder = builder.placeHolder;
        this.transform = builder.transform;
        this.radius = builder.radius;
        this.thumbnail = builder.thumbnail;
        this.imgView = builder.imgView;
        this.needCache = builder.needCache;
    }

    public int getQuality() {
        return quality;
    }

    public String getUrl() {
        return url;
    }

    public int getError() {
        return error;
    }

    public int getPlaceHolder() {
        return placeHolder;
    }

    public int getTransform() {
        return transform;
    }

    public int getRadius() {
        return radius;
    }

    public float getThumbnail() {
        return thumbnail;
    }

    public ImageView getImgView() {
        return imgView;
    }

    public boolean isNeedCache() {
        return needCache;
    }

    public static class Builder {
        private int quality;  //图片质量 (RGB_565，ARGB_8888)
        private String url; //需要解析的url
        private int error; //当没有成功加载的时候显示的图片
        private int placeHolder; //正在加载的时候显示的图片
        private int transform; //对图片进行裁剪
        private int radius; //圆角图片角度
        private float thumbnail; //图片缩略比例
        private boolean needCache; //是否需要缓存图片
        private ImageView imgView;

        public Builder() {
            this.quality = ImageLoaderHelper.PIC_QUALITY_RGB_565;
            this.url = "";
            this.error = R.drawable.ic_default_error;
            this.placeHolder = 0;//默认不添加加载图片
            this.transform = ImageLoaderHelper.Transform_Defult;
            this.radius = 0;
            this.thumbnail = 0;
            this.needCache = true;
            this.imgView = null;
        }

        public Builder quality(int quality) {
            this.quality = quality;
            return this;
        }

        public Builder url(String url) {
            this.url = url;
            return this;
        }

        public Builder error(int error) {
            this.error = error;
            return this;
        }

        public Builder placeHolder(int placeHolder) {
            this.placeHolder = placeHolder;
            return this;
        }

        public Builder transform(int transform, int radius) {
            this.transform = transform;
            this.radius = radius;
            return this;
        }

        public Builder thumbnail(float thumbnail) {
            this.thumbnail = thumbnail;
            return this;
        }

        public Builder needCache(boolean needCache) {
            this.needCache = needCache;
            return this;
        }

        public Builder imgView(ImageView imgView) {
            this.imgView = imgView;
            return this;
        }

        public ImageLoader build() {
            return new ImageLoader(this);
        }

    }
}
